package net.sharpf2.api.interfaces;

import net.sharpf2.sfcore.client.Interface;
import net.sharpf2.api.game.Interfaces;
import net.sharpf2.api.types.Content;

/**
 * Handling the options tab
 * @author Sam Smekens
 */
public class Options {
    
    /**
     * Return the actual interface object for the combat tab.
     * @return Content<Interface>
     */
    public static Content<Interface> getInterface() {
        return Interfaces.get(Constants.OPTIONS_TAB, 0);
    }
    
    /**
     * Returns the children of the combat tab.
     * @return Interface array.
     */
    public static Interface[] getChildren() {
        return getInterface().getContent().getChildren();
    }
    
    /**
     * Method to click a button in the Combat tab.
     * @param button    ID of the button, use the Constants class to indicate the ID
     */
    public static void clickButton(int button) {
        Tabs.checkAndOpen(Constants.OPTIONS_TAB);
        Content<Interface> btn = Interfaces.get(Constants.OPTIONS_TAB, button);
        if (btn != null) {
            btn.getActions().click();
        }
    }
    /**
     * Checks if a button is enabled or not.
     * @param   button  Use Constants class to indicate what button to check whether is enabled or not.
     * @return  true if is enabled otherwise false.
     */
    public static boolean isEnabled(int button){
        Tabs.checkAndOpen(Constants.OPTIONS_TAB);
        Content<Interface> btn = Interfaces.get(Constants.OPTIONS_TAB, button);
        for (int i=0; i<Constants.TEXTURES_ON.length; i++) {
            if (Constants.TEXTURES_ON[i] == btn.getContent().getTextureId()) {
                return true;
            }
        }
        return false;
    }
    /**
     * 
     * @param buttonID  ID of the button, use the Constants class to indicate the ID
     * @param enable    Enable or Disable the button
     */
    public static void toggleButton(int buttonID, boolean enable){
        if(!isEnabled(buttonID) && enable) {
            clickButton(buttonID);
        } else if(isEnabled(buttonID) && !enable) {
            clickButton(buttonID);
        }
    }
    
    public static class Constants {
        public final static int OPTIONS_TAB = 261;
        public final static int BUTTON_PROFANITY_FILTER = 3;
        public final static int BUTTON_CHAT_EFFECTS = 4;
        public final static int BUTTON_CHAT_SETUP = 5;
        public final static int BUTTON_MOUSE_NUMBERS = 6;
        public final static int BUTTON_ACCEPT_AID = 7;
        public final static int BUTTON_HOUSE_OPTIONS = 8;
        public final static int BUTTON_GRAPHICS_SETTINGS = 14;
        public final static int BUTTON_AUDIO_SETTINGS = 16;
        public final static int TEXTURES_ON[] = {
                                                 4583, //Profanity filter
                                                 762 //Accept Aid
                                                };
        public final static int TEXTURES_INDEX[] = {};
    }
}
